/*
 *  Copyright (C) 2010 Zubanov Dmitry
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 *
 * @author Zubanov Dmitry aka javadimon, zubanov@gmail.com
 * Omsk, Russia, created 16.09.2010
 * (C) Copyright by Zubanov Dmitry
 */

package org.jssdb.core.filesystem;

import java.io.Serializable;
import java.text.MessageFormat;
import org.jssdb.core.ram.RamHandler;

public class FileObjectInfo implements Serializable{
    
    private String className, fileName;
    private long lastModified, CRC32;
    private Object object;

    public FileObjectInfo(String className, String fileName, long lastModified, long CRC32) {
        this.className = className;
        this.fileName = fileName;
        this.lastModified = lastModified;
        this.CRC32 = CRC32;
    }

    public Object getObject() {
        return object;
    }

    public void setObject(){
        object = RamHandler.getInstance().getObjectById(Long.parseLong(fileName), className);
    }

    public long getCRC32() {
        return CRC32;
    }

    public void setCRC32(long CRC32) {
        this.CRC32 = CRC32;
    }

    public long getLastModified() {
        return lastModified;
    }

    public void setLastModified(long lastModified) {
        this.lastModified = lastModified;
    }

    public String getClassName() {
        return className;
    }

    public String getFileName() {
        return fileName;
    }

    @Override
    public String toString(){
        return MessageFormat.format("Class name {0}, File name {1}, "
                + "Last modified {2}, "
                + "CRC32 {3}", new Object[]{className, fileName,
                lastModified, CRC32});
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FileObjectInfo other = (FileObjectInfo) obj;
        if ((this.className == null) ? (other.className != null) : !this.className.equals(other.className)) {
            return false;
        }
        if ((this.fileName == null) ? (other.fileName != null) : !this.fileName.equals(other.fileName)) {
            return false;
        }
        if (this.lastModified != other.lastModified) {
            return false;
        }
        if (this.CRC32 != other.CRC32) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        return hash;
    }

}
